package com.platform.system.controller;

import com.platform.common.bean.Result;
import com.platform.common.controller.BaseController;
import com.platform.common.menus.ResultCodeEnum;
import com.platform.system.controller.role.RoleApiController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.hateoas.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;

/**
 * describe:超媒体api
 *
 * @author rainly
 * @date 2020/01/09
 * @time 5:32 下午
 */
@Api(value = "超媒体Api", tags = {"超媒体Api"})
@RestController
@RequestMapping(value = "/hateoas")
public class HateoasController extends BaseController {
    /**
     * 超媒体（HATEOAS）
     *
     * @return
     */
    @ApiOperation(value = "超媒体（HATEOAS）", httpMethod = "GET")
    @GetMapping
    public Resource<Result> serviceInfo() {
        Result result = new Result(ResultCodeEnum.SUCCESS);
        return new Resource<>(result
                , linkTo(methodOn(RoleApiController.class).getRoleList(0, 10))
                //表示这个API与当前网址的关系
                .withRel("roleList")
                //可选项，用来表明资源的语言
                .withHreflang("JSON")
                //请求类型
                .withMedia(MediaType.TEXT_HTML_VALUE)
                //可选项，用用户可读的语音来描述资源的主题
                .withTitle("角色分页")
                //可选项，它用来表示资源类型
                .withType("GET")
                //可选项，表示该对象会在未来废弃
                .withDeprecation("")
                , linkTo(methodOn(RoleApiController.class).delRoleById("1")).withRel("delRoleById")
        );
    }
}
